package shiyl.use.springboot.requestparam.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * 将拦截器注入拦截器管理中
 * @author shiyl
 */
@Slf4j
@Configuration
public class ConfigInterceptor extends WebMvcConfigurationSupport {

    @Autowired
    private ShowInfoHandlerInterceptor showInfoHandlerInterceptor;

    String[] includePatterns = {"/**"};
    String[] excludePatterns = {} ;

    /**
     * 注入拦截器
     *
     * @param registry
     * @see InterceptorRegistry
     */
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        log.info("添加拦截器:ShowInfoHandlerInterceptor");
        registry.addInterceptor(showInfoHandlerInterceptor)
                // addPathPatterns 用于添加拦截规则
                .addPathPatterns(includePatterns)
                // excludePathPatterns 用户排除拦截
                .excludePathPatterns(excludePatterns);
        // 多个拦截器组成一个拦截器链
//        registry.addInterceptor(more...).addPathPatterns().excludePathPatterns() ;

        super.addInterceptors(registry);
    }
}
